/**
 * @desc 用户
 */

'use strict'

const MODEL_NAME = 'user'
const COLLECTION_NAME = 'users'

module.exports = app => {
  const mongoose = app.mongoose
  const Schema = mongoose.Schema

  const UserSchema = new Schema({
    username: {
      type: String,
      default: '',
      required: true,
      trim: true,
    },
    password: { type: String, default: '', required: true },
    // 用户权限 admin-管理员, account-普通用户
    role: { type: String, enum: ['admin', 'account'], default: 'account' },

    nickname: { type: String, default: '' },
    avatar: { type: String, default: undefined },
    gender: {
      type: String,
      enum: ['male', 'female', 'unknow'],
      default: 'unknow',
    },
    cv: { type: String, default: '' }, // 简历
    desc: { type: String, default: '' }, // 描述/口头禅

    createdAt: { type: Date, default: Date.now },
    updatedAt: { type: Date, default: Date.now },
  })

  return mongoose.model(MODEL_NAME, UserSchema, COLLECTION_NAME)
}
